<?
require_once("../config/dbconn.php");require_once("../config/usercls.php");require_once("../config/pagecls.php");require_once("pwd1cls.php");
if($glo_closejjtobd==1)  
{	echo "<script>alert('奖金币转出已经关闭\\n');location.href='announce_lst.php';</script>";
	exit();
}

if($action=='del'){
	$db->delete("{$db_prefix}transfer","id='$id'");
	echo "<script>location.href='trans_bd.php?pageno={$pageno}';</script>";exit();
}

$sqlhy="select * from {$db_prefix}users where id='".$_SESSION['sys_userid']."'";
$rshy=$db->get_one($sqlhy);


if($act=='transdo'){
	$msg='';
	if(floatval($price)<=0) $msg.="请输入转账金额\\n";
	else{
		if(floatval($price)<$glo_jjzdzblower) $msg.="金额不能低于".$glo_jjzdzblower."\\n";
		else{
			if ((floatval($price)%$glo_bdbs)>0){
				$msg.="金额必须是{$glo_bdbs}的倍数\\n";
			}
		}
	}
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	if ($rshy['jjprice']<floatval($price)) $msg.="您没有足够的 奖金币余额\\n";
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	//如果没有扣除网络维护费。不能转账
	/*$sqlwhf="select * from {$db_prefix}yearf where userid='".$_SESSION['sys_userid']."'";
	$rswhf=$db->get_one($sqlwhf);
	if (!$rswhf['id']){
		 $msg.="没有扣除网络维护费。不能转账\\n";
	}
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}*/
	
	$feiyong=0;
	$feiyong=floatval($price)*$glo_jjtransrate/100;
	$realprice=floatval($price)-$feiyong;
	
	//扣款。转报单币
	if ($toptype==1){
	$sqlkk="update {$db_prefix}users set jjprice=jjprice-'".floatval($price)."',price=price+'".$realprice."' where id='".$_SESSION['sys_userid']."'";
	$db->query($sqlkk);	
	//财务记录
	$e_userid=$_SESSION['sys_userid'];$e_price=-floatval($price);$e_type=6;$e_ptype=3;$e_addtime=$curtime;$e_memo="奖金币转出报单币";
	hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	$e_userid=$_SESSION['sys_userid'];$e_price=$realprice;$e_type=6;$e_ptype=1;$e_addtime=$curtime;$e_memo="奖金币转出报单币";
	hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	}
	
	if ($toptype==5){
	$sqlkk="update {$db_prefix}users set jjprice=jjprice-'".floatval($price)."',gwprice=gwprice+'".$realprice."' where id='".$_SESSION['sys_userid']."'";
	$db->query($sqlkk);	
	//财务记录
	$e_userid=$_SESSION['sys_userid'];$e_price=-floatval($price);$e_type=8;$e_ptype=3;$e_addtime=$curtime;$e_memo="奖金币转出购物券";
	hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	$e_userid=$_SESSION['sys_userid'];$e_price=$realprice;$e_type=8;$e_ptype=5;$e_addtime=$curtime;$e_memo="奖金币转入购物券";
	hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	}
	
	//插入数据库
	$dataArray['username']=$_SESSION['sys_username'];
	$dataArray['price']=floatval($price);
	$dataArray['feiyong']=$feiyong;
	$dataArray['memo']=addslashes($memo);
	$dataArray['toptype']=$toptype;
	$dataArray['addtime']=$curtime;
	$db->insert("{$db_prefix}transfer",$dataArray);
	echo "<script>alert(' 奖金币转出成功');location.href='trans_bd.php';</script>";exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
		background-image: url(image1/bg-body.png);
}
td{
font-size:12px;
}
.red{
	color:#FF0000
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg1.png"><img src="images/left-top-right1.png" width="17" height="29" /></td>
    <td width="100%" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">&nbsp;&nbsp;奖金币转报单币或购物券</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.png"><img src="images/nav-right-bg.png" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg1.png">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td class="left_bt2"><form id="form1" name="form1" method="post" action="?act=transdo">
                    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#F7F8F9">
					<tbody bgcolor="#FFFFFF">
                      <tr>
                        <td colspan="3"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                            <tr>
                              <td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;您的 奖金币余额：
                                <?=$rshy['jjprice']?>
                                人民币/RMB. ￥</td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td height="30" colspan="3"><table width="100%" height="90" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td height="30" align="center" class="left_txt">转到账户：</td>
                              <td height="30" class="left_txt"><select name="toptype">
							  <option value="1">报单币</option>
                              <option value="5">购物券</option>
							  </select>
                              </td>
                            </tr>
                            <tr>
                              <td height="30" align="center" class="left_txt">金额：</td>
                              <td height="30" class="left_txt"><label>
                                <input name="price" type="text" id="price" size="10" value="">
                                人民币/RMB. ￥ <span class="red">*最小金额 <?=$glo_jjzdzblower?>元，且必须是<?=$glo_bdbs?>的倍数。
                                  <? if ($glo_jjtransrate>0) {?>
                                  现金转账手续费/Cash transfer fees：
                                  <?=$glo_jjtransrate?>
                                  %
                                  <? }?>
                                </span></label></td>
                            </tr>
                            <tr>
                              <td height="30" align="center" class="left_txt">说明：</td>
                              <td height="30" class="left_txt"><label>
                                <textarea name="memo" cols="40" rows="6" id="memo"><?=stripslashes($rs['memo'])?></textarea>
                              </label></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td height="30" colspan="3">&nbsp;</td>
                      </tr>
                      <tr>
                        <td width="50%" height="30" align="right"><input type="submit" value="确定转账" name="B1" /></td>
                        <td width="6%" height="30" align="right">&nbsp;</td>
                        <td width="44%" height="30"><input type="reset" value="取消设置" name="B12" /></td>
                      </tr>
                      <tr>
                        <td height="30" colspan="3">&nbsp;</td>
                      </tr>
					  </tbody>
                    </table>
                  </form></td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td height="30"><table width="100%" height="60" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="30" align="center" bgcolor="#f2f2f2" >编号</td>
                  <td align="center" bgcolor="#f2f2f2" >转入账户类型</td>
                  <td align="center" bgcolor="#f2f2f2" >金额</td>
                  <td align="center" bgcolor="#f2f2f2" >费用</td>
                  <td align="center" bgcolor="#f2f2f2" >实际金额</td>
                  <td align="center" bgcolor="#f2f2f2" >转账时间</td>
                  <td height="30" align="center" bgcolor="#f2f2f2" >操作</td>
                  </tr>
  <?
  $query='';
  if ($action=='query'){
  	
  }
  $sql="select count(id) as c  from {$db_prefix}transfer where (toptype=1 or toptype=5) and username='".$_SESSION['sys_username']."'";
  if ($query!='') $sql.=$query;
  $rs=$db->get_one($sql);
  $page=new pagecls(20,intval($rs['c']));
  $sql="select * from {$db_prefix}transfer where (toptype=1 or toptype=5)  and username='".$_SESSION['sys_username']."'";
  if ($query!='') $sql.=$query;
  $sql.=" order by id desc limit {$page->pastnum},{$page->pagesize}";
  $result=$db->query($sql);
  while($rs=$db->fetch_array($result)){
  ?>
                <tr>
                  <td align="center"><?=$rs['id']?></td>
                  <td align="center"><?=$hypricetypeary[$rs['toptype']]?></td>
                  <td align="center"><?=$rs['price']?>                      </td>
                  <td align="center" ><?=$rs['feiyong']?></td>
                  <td align="center" ><?=$rs['price']-$rs['feiyong']?></td>
                  <td align="center" ><?=date("Y-m-d H:i:s",$rs['addtime'])?></td>
                  <td height="30" align="center" ><a href="?action=del&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">删除</a></td>
                  </tr>
	<?
  }
  $db->free_result($result);
  ?>
              </table></td>
            </tr>
            
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
            <tr>
              <td height="30" align="right">每页
                <?=$page->pagesize?>
                条 第
                <?=$page->pageno?>/<?=$page->pagenum?>
                页 共
                <?=$page->recnum?>                条 <a href='?<?=$page->url?>1'><img src="image1/first.gif" border="0"></a>   <a href='?<?=$page->url.($page->pageno-1)?>'><img src="image1/back.gif" border="0"></a>  <a href='?<?=$page->url.($page->pageno+1)?>'><img src="image1/next.gif" border="0"></a>   <a href='?<?=$page->url.$page->pagenum?>'><img src="image1/last.gif" border="0"></a></td>
              </tr>
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.png">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.png"><img src="images/buttom_left2.png" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.png"><img src="images/buttom_bgs.png" width="17" height="17" /></td>
    <td background="images/mail_rightbg.png"><img src="images/buttom_right2.png" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>
